package com.wicket.okrapp.common.exception;

import org.apache.commons.lang3.StringUtils;

import java.util.Collection;


/**
 * @author ：CHS
 * @since 2023/02/18 13:16
 *
 *
 * @version 1.0
 */
public abstract class Assert {

    private Assert() {
    }

    public static void isFail(boolean success, String msg, boolean isErrLog) {
        isTrue(!success, msg, isErrLog);
    }

    public static void isTrue(boolean success, String msg, boolean isErrLog) {
        if (success) {
            throw new BizException(msg, isErrLog);
        }
    }

    public static void isBlank(String str, String msg, boolean isErrLog) {
        isTrue(StringUtils.isBlank(str), msg, isErrLog);
    }

    public static void isNotBlank(String str, String msg, boolean isErrLog) {
        isTrue(StringUtils.isNotBlank(str), msg, isErrLog);
    }

    public static void isNull(Object object, String msg, boolean isErrLog) {
        isTrue(object == null, msg, isErrLog);
    }

    public static void isNotNull(Object object, String msg, boolean isErrLog) {
        isTrue(object != null, msg, isErrLog);
    }

    public static void isNull(Collection<?> collection, String msg, boolean isErrLog) {
        isTrue(collection == null || collection.isEmpty(), msg, isErrLog);
    }

    public static void isNotEquals(Object a, Object b, String msg, boolean isErrLog) {
        isTrue(!a.equals(b), msg, isErrLog);
    }

    public static void isNotEquals(double a, double b, String msg, boolean isErrLog) {
        isTrue(a != b, msg, isErrLog);
    }

    public static void isEquals(Object a, Object b, String msg, boolean isErrLog) {
        isTrue(a.equals(b), msg, isErrLog);
    }

    public static void isEquals(Number a, Number b, String msg, boolean isErrLog) {
        isTrue(a.doubleValue() == b.doubleValue(), msg, isErrLog);
    }

    public static <T> void isNotContains(Collection<T> collection, T o, String msg, boolean isErrLog) {
        isTrue(!collection.contains(o), msg, isErrLog);
    }

    public static <T> void isContains(Collection<T> collection, T o, String msg, boolean isErrLog) {
        isTrue(collection.contains(o), msg, isErrLog);
    }

    public static void isGreatThan(Number a, Number b, String msg, boolean isErrLog) {
        isTrue(a.doubleValue() > b.doubleValue(), msg, isErrLog);
    }

    public static void isGreatAndEqual(Number a, Number b, String msg, boolean isErrLog) {
        isTrue(a.doubleValue() >= b.doubleValue(), msg, isErrLog);
    }

    public static void isLessThan(Number a, Number b, String msg, boolean isErrLog) {
        isTrue(a.doubleValue() < b.doubleValue(), msg, isErrLog);
    }

    public static boolean isNullOrEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

}
